﻿// ControlDlg.cpp: 实现文件
//

#include "pch.h"
#include "ProjectAA.h"
#include "ControlDlg.h"
#include "afxdialogex.h"


// CControlDlg 对话框

IMPLEMENT_DYNAMIC(CControlDlg, CDialogEx)

CControlDlg::CControlDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_DIALOG_CONTROL, pParent)
{

}

CControlDlg::~CControlDlg()
{
}

void CControlDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_TAB1, m_tabControl);
}


BEGIN_MESSAGE_MAP(CControlDlg, CDialogEx)
	ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, &CControlDlg::OnTcnSelchangeTab1)
END_MESSAGE_MAP()


// CControlDlg 消息处理程序


BOOL CControlDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	m_tabControl.InsertItem(0, L"10站_上料");
	m_tabControl.InsertItem(1, L"20站_点胶");

	//关联对话框,并且将IDC_TABTEST控件设为父窗口
	m_cControlDlg0.Create(IDD_DIALOG_CONTROL_10, GetDlgItem(IDC_TAB1));
	m_cControlDlg2.Create(IDD_DIALOG_CONTROL_20_2, GetDlgItem(IDC_TAB1));

	//获得IDC_TABTEST客户区大小
	CRect rs;
	m_tabControl.GetClientRect(&rs);
	//调整子对话框在父窗口中的位置
	rs.top += 25;
	//rs.bottom -= 60;
	rs.left += 1;
	rs.right -= 2;

	//设置子对话框尺寸并移动到指定位置
	m_cControlDlg0.MoveWindow(&rs);
	m_cControlDlg2.MoveWindow(&rs);
	//分别设置隐藏和显示
	m_cControlDlg0.ShowWindow(true);
	m_cControlDlg2.ShowWindow(false);
	//设置默认的选项卡
	m_tabControl.SetCurSel(0);
	return TRUE;
}


void CControlDlg::OnCancel()
{
	m_cControlDlg0.ShowWindow(false);
	m_cControlDlg2.ShowWindow(false);

	CDialogEx::OnCancel();
}


void CControlDlg::OnTcnSelchangeTab1(NMHDR *pNMHDR, LRESULT *pResult)
{
	int CurSel = m_tabControl.GetCurSel();
	switch (CurSel)
	{
	case 0:
		m_cControlDlg0.ShowWindow(true);
		m_cControlDlg2.ShowWindow(false);
		break;
	case 1:
		m_cControlDlg0.ShowWindow(false);
		m_cControlDlg2.ShowWindow(true);
		break;
	}
	*pResult = 0;
}
